package br.com.j7.jdesk.persistence.repository.impl;

import java.util.List;

import br.com.j7.jdesk.library.exception.RepositoryException;
import br.com.j7.jdesk.persistence.entity.Enterprises;
import br.com.j7.jdesk.persistence.entity.UsersGroups;
import br.com.j7.jdesk.persistence.repository.UserGroupRepository;

/**
 * 
 * 
 * @author Edivando Alves
 *
 */
public class UserGroupRepositoryImpl  extends AbstractRepository<UsersGroups> implements UserGroupRepository{


	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.impl.AbstractRepository#find(java.lang.Integer)
	 */
	@Override
	public UsersGroups find(Integer id) throws RepositoryException {
		try {
			return getEntity(UsersGroups.class, id);
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.UserGroupRepository#findByUserGroup(java.lang.String, br.com.j7.jdesk.persistence.entity.Enterprises)
	 */
	@Override
	public UsersGroups findByUserGroup(String cdUserGroup, Enterprises enterprise) throws RepositoryException {
		try {
			return getEntity(UsersGroups.class, "userGroupByCdUserGroupAndEnterprise", cdUserGroup, enterprise);
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}

	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.impl.AbstractRepository#list()
	 */
	@Override
	public List<UsersGroups> list() throws RepositoryException {
		try {
			return listByNamedQuery(UsersGroups.class,"userGroup");
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}
	
	/*
	 * (non-Javadoc)
	 * @see br.com.j7.jdesk.persistence.repository.UserGroupRepository#listByEnterprise(br.com.j7.jdesk.persistence.entity.Enterprises)
	 */
	@Override
	public List<UsersGroups> listByEnterprise(Enterprises enterprise) throws RepositoryException{
		try {
			return listByNamedQuery(UsersGroups.class, "userGroupByEnterprise", enterprise);
		} catch (RepositoryException e) {
			throw new RepositoryException(e);
		}
	}
}






